import axios from "axios";
import { hostUrl } from "../config";

class HttpService {
  constructor(baseUrl = baseUrl) {
    this.baseUrl = baseUrl;
  }

  getInsideConfig() {
    const config = {
      baseUrl: this.baseUrl
    };
    return config;
  }

  interceptors(instance) {
    instance.interceptors.response.use(res => {
      const data = res.data;
      if (data.errcode != 200) {
        alert(data.errmsg);
      }
    });
  }

  request(options) {
    const instance = axios.create();
    instance.defaults.baseURL = this.baseUrl;
    // this.interceptors(instance, options.url);
    return instance(options);
  }
}

const service = new HttpService(hostUrl);

export default service;
